/**
 * 添加或者修改页面
 */
var PackageSizeInfoDlg = {
    data: {
        length: "",
        wide: "",
        tall: "",
        roughWeight: "",
        netWeight: "",
        volume: "",
        productOrderId: "",
        /*classification: "",
        name: "",
        id:""*/
    }
};


var getFloatStr = function(num){
    num += '';
    num = num.replace(/[^0-9|\.]/g, ''); //清除字符串中的非数字非.字符
    if(/^0+/) //清除字符串开头的0
       num = num.replace(/^0+/, '');
    if(!/\./.test(num)) //为整数字符串在末尾添加.00
       num += '.00';
    if(/^\./.test(num)) //字符以.开头时,在开头添加0
       num = '0' + num;
    num += '00';        //在字符串末尾补零
    num = num.match(/\d+\.\d{2}/)[0];
    return num;
};

layui.use(['form', 'admin', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;

    //让当前iframe弹层高度适应
    admin.iframeAuto();
    $("#name_1").click(function () {
        console.log("fffff");
        var formName = encodeURIComponent("parent.PackageSizeInfoDlg.data.name");
        var formId = encodeURIComponent("parent.PackageSizeInfoDlg.data.id");
        var treeUrl = encodeURIComponent(Feng.ctxPath + "/classification/getTree");

        layer.open({
            type: 2,
            title: '分类选择',
            area: ['300px', '450px'],
            content: Feng.ctxPath + '/system/commonTree?formName=' + formName + "&formId=" + formId + "&treeUrl=" + treeUrl,
            end: function () {
                $("#classification").val(PackageSizeInfoDlg.data.id);
                $("#name_1").val(PackageSizeInfoDlg.data.name);
            }
        });
    });



    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/packageSize/addItem", function (data) {
            Feng.success("添加成功！");
            window.location.href = Feng.ctxPath + '/packageSize'
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    //返回按钮
    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + '/packageSize'
    });


    $("#length").blur(function(){
        var num=$("#length").val();
        //alert("num????????"+num);
        var num1=getFloatStr(num);
        //alert("num1????????"+num1);
        $("#length").val(num1);
    });

    $("#wide").blur(function(){
        var num=$("#wide").val();
        //alert("num????????"+num);
        var num1=getFloatStr(num);
        //alert("num1????????"+num1);
        $("#wide").val(num1);
    });

    $("#tall").blur(function(){
        var num=$("#tall").val();
        //alert("num????????"+num);
        var num1=getFloatStr(num);
        //alert("num1????????"+num1);
        $("#tall").val(num1);
    });

    $("#roughWeight").blur(function(){
        var num=$("#roughWeight").val();
        //alert("num????????"+num);
        var num1=getFloatStr(num);
        //alert("num1????????"+num1);
        $("#roughWeight").val(num1);
    });

    $("#netWeight").blur(function(){
        var num=$("#netWeight").val();
        //alert("num????????"+num);
        var num1=getFloatStr(num);
        //alert("num1????????"+num1);
        $("#netWeight").val(num1);
    });
});